package com.donn.securitycontrolplatform.elefence.controller;


import com.donn.securitycontrolplatform.common.Result;
import com.donn.securitycontrolplatform.elefence.Response.Response;
import com.donn.securitycontrolplatform.elefence.request.ElefenceCreateReq;
import com.donn.securitycontrolplatform.elefence.request.ElefenceQueryReq;
import com.donn.securitycontrolplatform.elefence.request.ElefenceUpdateReq;
import com.donn.securitycontrolplatform.elefence.service.ITElefenceService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 电子围栏前端控制器
 * </p>
 *
 * @author zhenglx
 * @since 2022-06-21
 */
@RestController
@RequestMapping("/scp/api/elefence")
@Tag(name = "ElefenceController", description = "电子围栏Controller")
public class TElefenceController {

    @Autowired
    ITElefenceService service;

    @ApiOperation(value = "新增电子围栏")
    @PostMapping(value = "/add")
    @ResponseBody
    public Response add(ElefenceCreateReq elefence) {
        return service.insertElefence(elefence);
    }

    @ApiOperation(value = "修改电子围栏")
    @PostMapping("/update")
    @ResponseBody
    public Response update(ElefenceUpdateReq elefence) {
        return service.updateElefence(elefence);
    }

    @ApiOperation(value = "删除电子围栏")
    @PostMapping("/delete")
    @ResponseBody
    public Response delete(@RequestParam("id") String elefenceId) {
        return service.deleteElefence(elefenceId);
    }

    @ApiOperation(value = "查询电子围栏列表")
    @PostMapping("/list")
    @ResponseBody
    public Response list(ElefenceQueryReq queryReq) {
        return service.selectElefenceList(queryReq);
    }

    @ApiOperation(value = "电子围栏详情")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "elefenceId", value = "角色Id")
    })

    @GetMapping("/get")
    @ResponseBody
    public Response get(@RequestParam String elefenceId) {
        return service.getElefenceById(elefenceId);
    }


    @ApiOperation(value = "标签进入电子围栏")
    @PostMapping(value = "/entryEleFence")
    @ResponseBody
    public Result entryEleFence(@RequestParam String tagId, @RequestParam String fenceId) {
        return service.entryEleFence(tagId, fenceId);
    }

    @ApiOperation(value = "动态盘点")
    @GetMapping(value = "/dynamic/statistics/{fenceId}")
    @ResponseBody
    public Result dynamicStatistics(@RequestParam int time, @PathVariable String fenceId, @RequestParam String equipmentType) {
        return service.dynamicStatistics(time, fenceId, equipmentType);
    }

    @ApiOperation(value = "电子围栏实时人数")
    @GetMapping(value = "/dynamic/statistics/{fenceId}/persons/quantity")
    @ResponseBody
    public Result dynamicStatisticsPersonQuantity(@PathVariable String fenceId) {
        return service.dynamicStatisticsPersonQuantity(fenceId);
    }
}
